function createXML(messageObj) {
     
 
    var { Content,ToUserName, FromUserName, MsgType,CreateTime} = messageObj;
    //var CreateTime = new Date().getTime();
    var header = `<xml>
                    <ToUserName><![CDATA[${ToUserName}]]></ToUserName>
                    <FromUserName><![CDATA[${FromUserName}]]></FromUserName>
                    <CreateTime>${CreateTime}</CreateTime>
                    <MsgType><![CDATA[${MsgType}]]></MsgType>`;
    var content = '';
    switch(MsgType) {
        case 'text':
            
            content = `<Content><![CDATA[${Content}]]></Content>
                     </xml>`;
            break;
        case 'image':
            
            content = `<Image>
                         <MediaId><![CDATA[${Content.MediaId}]]></MediaId>
                       </Image>
                     </xml>`;
            break;
        case 'voice':
            
            content = `<Voice>
                         <MediaId><![CDATA[${Content.MediaId}]]></MediaId>
                       </Voice>
                     </xml>`;
            break;
        case 'video':
           
            content = `<Video>
                         <MediaId><![CDATA[${Content.MediaId}]]></MediaId>
                         <Title><![CDATA[${Content.Title}]]></Title>
                         <Description><![CDATA[${Content.Description}]]></Description>
                       </Video> 
                     </xml>`;
            break;
        case 'music':
        
            content = `<Music>
                         <Title><![CDATA[${Content.Title}]]></Title>
                         <Description><![CDATA[${Content.Description}]]></Description>
                         <MusicUrl><![CDATA[${Content.MusicUrl}]]></MusicUrl>
                         <HQMusicUrl><![CDATA[${Content.HQMusicUrl}]]></HQMusicUrl>
                         <ThumbMediaId><![CDATA[${Content.ThumbMediaId}]]></ThumbMediaId>
                       </Music>
                     </xml>`;
            break;
        case 'news':
             
            var ArticleCount = Content.length;
            content = `<ArticleCount>${ArticleCount}</ArticleCount><Articles>`;
            for (var i = 0; i < ArticleCount; i++) {
                content += `<item>
                                <Title><![CDATA[${Content[i].Title}]]></Title>
                                <Description><![CDATA[${Content[i].Description}]]></Description>
                                <PicUrl><![CDATA[${Content[i].PicUrl}]]></PicUrl>
                                <Url><![CDATA[${Content[i].Url}]]></Url>
                              </item>`;
            }
            content += '</Articles></xml>';
            break;
        default:
            content = `<Content><![CDATA[Error]]></Content>
                     </xml>`;
    }
    
    var xml = header + content;
    return xml;
}

module.exports = createXML;